//
//  TTExtractAddressViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/9/29.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTExtractAddressViewCell.h"

@interface TTExtractAddressViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *addressImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;

@property (nonatomic, assign) BOOL isChangeAddress;

@property (nonatomic, strong) TTAddressModel *model;

@end

@implementation TTExtractAddressViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.lineView.hidden = YES;
}

- (void)setModel:(TTAddressModel *)model isChangeAddress:(BOOL)isChangeAddress
{
    _model = model;
    _isChangeAddress = isChangeAddress;
    
    self.titleLabel.text = model.title;
    self.contentLabel.text = model.Address;
    
    if (model.isOpen) {
        self.titleLabel.textColor = UIColorHex(333333);
//        self.lineView.hidden = NO;
        self.phoneBtn.hidden = NO;
        [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.addressImageView.mas_right).mas_offset(10);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-50);
        }];
    } else {
        self.titleLabel.textColor = UIColorHex(999999);
//        self.lineView.hidden = YES;
        self.phoneBtn.hidden = YES;
        [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.addressImageView.mas_right).mas_offset(10);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        }];
    }
    
//    if (isChangeAddress) {
//        [self.phoneBtn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
//        [self.phoneBtn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
//        self.phoneBtn.selected = model.isSelect;
//    }
    
//    self.phoneBtn.enabled = isChangeAddress;
    
    [self.phoneBtn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
    [self.phoneBtn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
    
    self.phoneBtn.selected = model.isSelect;
    
}

- (void)setListModel:(TTSendStoreListModel *)listModel
{
    _listModel = listModel;
    
    self.titleLabel.text = listModel.storeName;
    self.contentLabel.text = listModel.storeAddress;
    
    self.phoneBtn.hidden = NO;
//    self.phoneBtn.enabled = NO;
    
    [self.phoneBtn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
    [self.phoneBtn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
    
    self.phoneBtn.selected = listModel.isSelect;
    
}

- (IBAction)phoneButtonClick:(UIButton *)sender {
    
//    if (self.isChangeAddress) {
//        sender.selected = !sender.selected;
//        if (self.selectBlock) {
//            self.selectBlock(self, self.model);
//        }
//
//        return;
//    }
//    // 打电话
//    [self.model.ReceiverMobile callPhone];
    
    sender.selected = !sender.selected;
    
    if (self.listModel && self.selectStoreListBlock) {
        self.selectStoreListBlock(self, self.listModel);
    }
    
    if (self.model && self.selectBlock) {
        self.selectBlock(self, self.model);
    }
    
}


@end
 
